package com.twinkle.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.twinkle.dao.RegressionParamMapper;
import com.twinkle.model.RegressionParam;
import com.twinkle.model.RegressionParamUI;
import com.twinkle.service.RegressionParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;

/**
 * @title: ClassifierParamServiceImpl
 * @description:
 * @author: Paul
 * @date: 2023/3/17 14:56
 */
@Service
public class RegressionParamServiceImpl implements RegressionParamService {

    @Autowired
    RegressionParamMapper regressionParamMapper;

    @Override
    public String addRegressionParam(RegressionParamUI regressionParamUI) throws ParseException {
        RegressionParam regressionParam = new RegressionParam();
        regressionParam.setId(regressionParamUI.getId());
        regressionParam.setAppName(regressionParamUI.getAppName());
        regressionParam.setDataSourceId(regressionParamUI.getDataSourceId());
        regressionParam.setTableName(regressionParamUI.getTableName());
        regressionParam.setFeatureCols(JSONObject.toJSONString(regressionParamUI.getFeatureCols()));
        regressionParam.setClassCols(JSONObject.toJSONString(regressionParamUI.getClassCols()));
        regressionParam.setPreProcessMethodList(JSONObject.toJSONString(regressionParamUI.getPreProcessMethodList()));
        regressionParam.setAlgoParam(JSONObject.toJSONString(regressionParamUI.getAlgoParam()));
        regressionParam.setTrainDataRatio(regressionParamUI.getTrainDataRatio());
        int insert = regressionParamMapper.insert(regressionParam);
        return "sucess";
    }
}
